<?php

/**
 * Description of emailHeaderFooterSaveAction
\* www.teuker.nl - mail@teuker.nl
 * 
 * @author francisc
 */

class emailHeaderFooterSaveAction extends sfAction {

    public function execute($request) {
        $this->form = new EmailHeaderFooterForm();

        if ($this->processEmailHeaderFooter($request, $this->form)) {
            SqlEngineCore::get()->update(array(
                                    'table' => 'settings',
                                    'columns' => array(
                                        'email_header' => $this->form->getValue('header'),
                                        'email_footer' => $this->form->getValue('footer')),
                                    'where' => array(
                                        'restaurant_id' => $this->getUser()->getAttribute('current_restaurant_id'))));

            $this->error = 0;
        }
        else {
            $this->error = 1;
        }
    }

    protected function processEmailHeaderFooter(sfWebRequest $request, sfForm $form) {
        $form->bind($request->getParameter($form->getName()));

        return $form->isValid();
    }
}
